<?php


require_once 'core/abstract.db.php';

class logs extends db {
	
	public function logsList()
	{
		$this -> open();
		$this -> query("SELECT l.log_type AS log_type, l.log_size AS log_size, l.log_msg AS log_msg, c.character_name AS character_name
				FROM logs l
				LEFT JOIN characters c ON c.character_id = l.character_id
				WHERE log_date > (NOW() - INTERVAL 10 MINUTE) AND log_target = '" . $_SESSION['cid'] . "' ORDER BY log_date DESC");
		
		if($this -> numrows > 0)
		{
			$list = '<ul class="list-group">';
			while($rd = $this -> fetch()) 
			{
				
				$log_size		= trim(htmlentities($rd['log_size']));
				$log_from 		= trim(htmlentities($rd['character_name']));
				$log_type		= trim(htmlentities($rd['log_type']));
				$log_msg 		= trim(htmlentities($rd['log_msg']));
				
				switch ($log_type)
				{
					case 1:
						$list .= '<li class="list-group-item">' . $log_size . '</strong> exp ricevuti da ' . $log_from . '</li>';
					break;
					case 3:
						$item_name = explode(";", $row['log_msg']);
						$item_name = $item_name[0];
							$list .= '<li class="list-group-item">' . $log_size . ' <strong>' . $item_name . '</strong> ricevuti da ' . $log_from . '</li>';
					break;
				}
				
			}
			$list .= '</ul>';
			
			return trim($list);
		} else {
			return FALSE;
		}
		
	}
	
}